package indi.matcha.csmallproducttest.service.impl;

import indi.matcha.csmallproducttest.mapper.PmsAlbumMapper;
import indi.matcha.csmallproducttest.pojo.dto.PmsAlbumDTO;
import indi.matcha.csmallproducttest.pojo.entity.PmsAlbum;
import indi.matcha.csmallproducttest.pojo.vo.PmsAlbumStandardVO;
import indi.matcha.csmallproducttest.service.PmsAlbumService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PmsAlbumServiceImpl implements PmsAlbumService {
    @Autowired
    PmsAlbumMapper PmsAlbumMapper;


    @Override
    public int countByName(PmsAlbumDTO pmsAlbumDTO) {
        String name = pmsAlbumDTO.getName();
        int countByName = PmsAlbumMapper.countByName(name);
        if (countByName > 0){
            String message = "添加相册失败,相册名称已经被占用！";
                    throw new RuntimeException();
        }

        PmsAlbum pmsAlbum = new PmsAlbum();
        BeanUtils.copyProperties(pmsAlbumDTO,pmsAlbum);
        return countByName;
    }

    @Override
    public PmsAlbumStandardVO getStandardById(Long id) {
        return PmsAlbumMapper.getStandardById(id);
    }

    @Override
    public int countByNameAndNotId(Long id, String name) {
        return PmsAlbumMapper.countByNameAndNotId(id, name);
    }
}
